<template>
	<el-container>
		<el-header style="font-size: 16px;font-weight: 600">预算参数设置</el-header>
		<el-main class="nopadding">
			<el-main>
				<el-form>
					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="费用上报方式" label-width="150px">
								<el-radio-group v-model="form.costUpdateType">
									<el-radio-button label="1">系统填报审批方式</el-radio-button>
									<el-radio-button label="2">BPM流程审批方式</el-radio-button>
								</el-radio-group>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">费用上报复杂的场景可以使用BPM流程方式，可以像正常审批流程一样上报预算费用！</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24" v-if="form.costUpdateType=='2'">
						<el-col :lg="12">
							<el-form-item label="费用上报流程" label-width="150px">
								<el-select v-model="form.flowIdUpdate" clearable>
									<el-option v-for="item in flowOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用户费用上报的BPM流程</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="费用申请方式" label-width="150px">
								<el-radio-group v-model="form.costApplayType">
									<el-radio-button label="1">系统填报审批方式</el-radio-button>
									<el-radio-button label="2">BPM流程审批方式</el-radio-button>
								</el-radio-group>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">费用申请复杂的场景可以使用BPM流程方式，可以像正常审批流程一样申请预算费用！</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24" v-if="form.costApplayType=='2'">
						<el-col :lg="12">
							<el-form-item label="费用申请流程" label-width="150px">
								<el-select v-model="form.flowIdCost" clearable>
									<el-option v-for="item in flowOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用户费用申请的BPM流程</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="费用申请审批人" label-width="150px">
								<select-user-dialog v-model:accountId="form.costApprovalUser" :mode="true"/>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用户费用申请的审批人，系统填报审批方式有效</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="预算是否直接调整" label-width="150px">
								<el-radio-group v-model="form.adjustmentType">
									<el-radio-button label="1">可直接调整预算</el-radio-button>
									<el-radio-button label="2">通过审批调整预算</el-radio-button>
								</el-radio-group>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">用户可以是否可以通过编辑项目详情的方式修改原本的预算</span>
							</el-form-item>
						</el-col>
					</el-row>

					<el-row :gutter="24">
						<el-col :lg="12">
							<el-form-item label="预算调整审批人" label-width="150px">
								<select-user-dialog v-model:accountId="form.adjustmentApprovalUser" :mode="true"/>
							</el-form-item>
						</el-col>
						<el-col :lg="12">
							<el-form-item>
								<span style="color: red;">预算调整通过的审批人，可直接调整预算有效</span>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>
			</el-main>
		</el-main>
		<el-footer class="footer">
			<el-button type="primary" @click="setBudgetConfig">设置</el-button>
		</el-footer>
	</el-container>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog";
export default {
	name: 'Budget Config Setting',
	components: {
		selectUserDialog,
	},
	data() {
		return {
			flowOptions: [],
			form: {
				costUpdateType: "1",
				flowIdUpdate:'',
				costApplayType: '1',
				flowIdCost: '',
				costApprovalUser: '0',
				adjustmentType: '1',
				adjustmentApprovalUser: '',
			},
		}
	},
	mounted() {
		this.getBpmFlowListForSelect();
		this.getBudgetConfig();
	},
	methods: {
		async getBpmFlowListForSelect() {
			var res = await this.$API.bpm.bpmFlow.getBpmFlowListForSelect.get({model:'0'});
			if (res.code == 200) {
				this.flowOptions = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async setBudgetConfig() {
			var res = await this.$API.finance.budget.setBudgetConfig.post(this.form);
			if (res.code == 200) {
				this.$message.success(res.message)
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getBudgetConfig() {
			var res = await this.$API.finance.budget.getBudgetConfig.get();
			if (res.code == 200) {
				if(res.data!=undefined)
				{
					this.form = res.data;
				}
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style scoped>
.footer {
	text-align: center;
}
</style>
